package com.hnkywl.sts.dao.zjgl;

import com.hnkywl.sts.entity.htgl.Cght;
import com.hnkywl.sts.entity.zjgl.Yypf;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.*;
import org.springframework.stereotype.Repository;
import java.util.Map;

/**
 * 说明：
 * 包:        com.hnkywl.sts.dao.zjgl
 * 类描述:    异议赔付dao类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 * Created by lw on 2015/11/4.
 */
@Repository
public class YypfDao extends SimpleHibernateTemplate<Yypf, Long> {

    /**
     * 查询异议赔付信息
     *
     * @param htbm     合同编号
     * @param pageNo
     * @param rowsSize
     * @return
     */
    public Page<Map> findAllYype(String htbm, int pageNo, int rowsSize) {
        Page<Yypf> page = new Page<Yypf>();
        page.setAutoCount(true);
        page.setPageNo(pageNo);
        page.setPageSize(rowsSize);
        page.setOrder("desc");
        page.setOrderBy("dateCreated");
        Criteria criteria = getSession().createCriteria(this.entityClass)
                .createAlias("ht", "ht", CriteriaSpecification.INNER_JOIN)
                .createAlias("gsjg", "gsjg", CriteriaSpecification.INNER_JOIN)
                .setProjection(Projections.projectionList()
                                .add(Property.forName("id").as("id"))
                                .add(Property.forName("ht.htbm").as("htbm"))
                                .add(Property.forName("gsjg.qc").as("kh"))
//                              .add(Projections.sqlProjection("this_.htbm as htbm", new String[]{"htbm"}, new Type[]{Hibernate.STRING}))
                                .add(Property.forName("yypfje").as("yypfje"))
                                .add(Property.forName("bz").as("bz"))
                                .add(Property.forName("syzt").as("syzt"))
                ).setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        if (StringUtils.isNotEmpty(htbm)) {
            criteria.add(Property.forName("ht.htbm").like(htbm.toUpperCase(), MatchMode.ANYWHERE));
        }
        Page list = this.findByCriteria(page, criteria);
        return list;
    }

    /**
     * 查询下拉合同列表
     *
     * @param pageNo
     * @param rows
     * @return
     */
    public Page<Cght> findXlht(int pageNo, int rows) {
        Page<Cght> page = new Page<Cght>();
        page.setAutoCount(true);
        page.setPageNo(pageNo);
        page.setPageSize(rows);
        page.setOrder("desc");
        page.setOrderBy("dateCreated");
        Criteria criteria = getSession().createCriteria(Cght.class)
                .createAlias("hzf", "hzf", CriteriaSpecification.INNER_JOIN)
                .setProjection(Projections.projectionList()
                                .add(Property.forName("id").as("id"))
                                .add(Property.forName("htbm").as("htbm"))
                                .add(Property.forName("jhdd").as("jhdd"))
                                .add(Property.forName("hzf.qc").as("hzf_qc"))
                                .add(Property.forName("qdrq").as("qdrq"))
                                .add(Property.forName("yfje").as("yfje"))
                ).setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        Page list = this.findByCriteria(page, criteria);
        return  list;
    }
}
